<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="6">
					<a-form-item label="姓名" name="name">
						<a-input v-model:value="searchFormState.name" placeholder="请输入姓名" />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="补卡时间" name="replenishmentTime">
						<a-month-picker
							v-model:value="searchFormState.replenishmentTime"
							value-format="YYYY-MM"
							placeholder="请选择日期"
							style="width: 100%"
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" @click="table.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			:alert="options.alert.show"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
			:row-selection="options.rowSelection"
		>
		</s-table>
	</a-card>
</template>

<script setup name="replacementlist">
	import sysReplacementListApi from '@/api/biz/sysReplacementListApi'
	import moment from 'moment'
	let searchFormState = reactive({
		replenishmentTime: moment().format('YYYY-MM')
	})
	const searchFormRef = ref()
	const table = ref()
	const formRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const columns = [
		{
			title: '姓名',
			dataIndex: 'name'
		},
		{
			title: '工号',
			dataIndex: 'userId'
		},
		{
			title: '补卡时间',
			dataIndex: 'replenishmentTime'
		},
		{
			title: '异常状态',
			dataIndex: 'abnormalState'
		},
		{
			title: '补卡事由',
			dataIndex: 'reason'
		}
	]
	const selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		// columns数字类型字段加入 needTotal: true 可以勾选自动算账
		alert: {
			show: true,
			clear: () => {
				selectedRowKeys.value = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}
	const loadData = (parameter) => {
		const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
		return sysReplacementListApi.sysReplacementListPage(Object.assign(parameter, searchFormParam)).then((data) => {
			return data
		})
	}
	// 重置
	const reset = () => {
		searchFormRef.value.resetFields()
		table.value.refresh(true)
	}
</script>
